<template>
  <div class="page">
    <a class="page-left" :class="{grayscale: serialNumber == 0}" @click="changeNumber(-1)"><img src="@/assets/images/testNext.png" alt=""></a>
    <a class="page-right" @click="changeNumber(1)"><img src="@/assets/images/testNext.png" alt=""></a>
    <div class="box">
      <div class="box-title">
        <img src="@/assets/images/testTitle1.png" alt="">
        <div>开始测试</div>
        <img src="@/assets/images/testTitle2.png" alt="">
      </div>
      <div class="progress-box">
        <div class="now-progress">第{{ serialNumber + 1 }}题</div>
        <div class="progress-list">
          <div class="progress-item" :class="{finish: index <= serialNumber, 'in-progress': inProgress && index == serialNumber}" v-for="(item, index) in questionList.length" :key="index"></div>
        </div>
        <div class="totle-progress">共约{{ questionList.length }}题</div>
      </div>
      <div class="question-info">
        <img v-if="questionInfo.subject == 1" class="question-subject" src="@/assets/images/subject1.png" alt="">
        <img v-if="questionInfo.subject == 2" class="question-subject" src="@/assets/images/subject2.png" alt="">
        <div class="question-title">{{ serialNumber + 1 }}.{{ questionInfo.title }}</div>
        <div class="question-option-list">
          <a v-for="itme in questionInfo.question" :key="itme.option"><div class="question-option-item">
            <span>{{ itme.option }}. </span>{{ itme.title }}
          </div></a>
        </div>
        <div v-if="questionInfo.type == 1">
          <div class="answer-title">请选择答（单选）</div>
          <div class="answer-list">
            <a
              v-for="itme in questionInfo.question"
              :key="itme.option"
              @click="changeAnswer(itme.option)"
            ><div class="answer-item" :class="{active: questionInfo.answer == itme.option}">{{ itme.option }}</div></a>
          </div>
        </div>
        <div v-if="questionInfo.type == 2">
          <div class="answer-title">请输入答案</div>
          <a-input 
            class="answer-input" 
            v-model:value="questionInfo.answer" 
            @blur="blurAnswer"
          />
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue'
import { useRouter } from 'vue-router'

const router = useRouter()
const serialNumber = ref(0)
const questionList = ref([
  {
    subject: 1,
    type: 1,
    title: '不少经典作品中都有“大闹”的情节。下列选项中哪一个评价不够恰当：',
    question: [
      {
        title: '鲁智深大闹野猪林(《水浒传》)--“闹”中见义',
        option: 'A'
      },
      {
        title: '孙行者大闹黑风山(《西游记》)--“闹”中显勇',
        option: 'B'
      },
      {
        title: '刘四爷大闹生日宴(《骆驼祥子》)--“闹”中有爱',
        option: 'C'
      },
      {
        title: '严贡生大闹船家(《儒林外史》)--“闹”中显诈',
        option: 'D'
      },
    ]
  },
  {
    subject: 2,
    type: 2,
    title: '王安石在《登飞来峰》中用“不畏浮云遮望眼，_______”表达自己锐意改革的远大政治抱负。',
    question: []
  },
])
const questionInfo = ref({})
const inProgress = ref(true)

const changeNumber = (n: number) => {
  if(n == -1 && serialNumber.value == 0) {
    return
  }
  if(n == 1 && serialNumber.value == questionList.value.length - 1) {
    router.push('/evaluationResults')
    return
  }
  serialNumber.value += n
  questionInfo.value = questionList.value[serialNumber.value]
  if(!questionList.value[serialNumber.value].answer) {
    inProgress.value = true
  }
}
const blurAnswer = (e) => {
  questionList.value[serialNumber.value].answer = e.target.value
  inProgress.value = false
  questionInfo.value = questionList.value[serialNumber.value]
}
const changeAnswer = (answer) => {
  questionList.value[serialNumber.value].answer = answer
  inProgress.value = false
  questionInfo.value = questionList.value[serialNumber.value]
}

onMounted(() => {
  questionInfo.value = questionList.value[serialNumber.value]
})
</script>

<style lang="scss" scoped>
.page {
  width: 100%;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 56px;
  padding: 10vh 20px;
  background-color: #F5F6F8;
  .page-left {
    position: fixed;
    left: 45px;
    top: calc(50% - 25px);
    width: 50px;
    height: 50px;
  }
  .page-right {
    position: fixed;
    right: 45px;
    top: calc(50% - 25px);
    width: 50px;
    height: 50px;
    transform: rotate(180deg);
  }
  .page-left.grayscale,
  .page-right.grayscale {
      filter: grayscale(100%);
  }

  .box {
    width: calc(100vw - 280px);
    border-radius: 6px;
    background: #FFF;
    padding: 30px 32px 128px;
    .box-title {
      display: flex;
      justify-content: center;
      align-items: center;
      gap: 30px;
      color: #333;
      font-size: 24px;
      font-weight: 600;
      margin-bottom: 20px;
      img {
        display: block;
        width: 96px;
        height: 22px;
      }
    }
    .progress-box {
      display: flex;
      align-items: center;
      gap: 20px;
      margin-bottom: 42px;
      .now-progress {
        width: 65px;
        color: #6F55FF;
        font-size: 20px;
        font-weight: 600;
      }
      .progress-list {
        flex: 1;
        display: flex;
        gap: 3px;
        .progress-item {
          flex: 1;
          height: 30px;
          border-radius: 4px;
          background: #EFEFEF;
          &:first-child {
            border-radius: 20px 4px 4px 20px;
          }
          &:last-child {
            border-radius: 4px 20px 20px 4px;
          }
        }
        .finish {
          background: #6F55FF;
        }
        .in-progress {
          background: rgba(111, 85, 255, 0.50);
        }
      }
      .totle-progress {
        font-size: 20px;
      }
    }
    .question-info {
      padding-left: 65px;
      position: relative;
      .question-subject {
        position: absolute;
        left: 0;
        top: 0;
        display: block;
        width: 45px;
        height: 45px;
      }
      .question-title {
        font-size: 24px;
        font-weight: 600;
        line-height: 34px;
        margin-bottom: 30px;
      }
      .question-option-list {
        height: 202px;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        margin-bottom: 78px;
        .question-option-item {
          font-size: 20px;
          span {
            color: #6F55FF;
          }
        }
      }
      .answer-title {
        font-size: 24px;
        font-weight: 600;
        margin-bottom: 22px;
      }
      .answer-list {
        display: flex;
        gap: 30px;
        .answer-item {
          width: 220px;
          height: 80px;
          line-height: 80px;
          flex-shrink: 0;
          border-radius: 10px;
          background: #EEE;
          font-size: 24px;
          text-align: center;
        }
        .active {
          background: #6F55FF;
          color: #FFF;
          position: relative;
          overflow: hidden;
          &::after {
            content: '';
            position: absolute;
            top: 22px;
            left: 133px;
            width: 112px;
            height: 112px;
            border-radius: 50%;
            background-color: rgba(255, 255, 255, 0.30);;
          }
        }
      }
      .answer-input {
        width: 970px;
        height: 80px;
        flex-shrink: 0;
        border-radius: 10px;
        border: 0.6px solid #D4D4D4;
        background: #FFF;
        color: #333;
        font-size: 24px;
      }
    }
  }
}
</style>